package com.lfs.market.controller.admin;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.lfs.market.model.R;
import com.lfs.market.model.dto.SystemUserLoginDto;
import com.lfs.market.model.entity.SystemRole;
import com.lfs.market.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 西尾ink
 * @version 1.0
 * @description TODO
 * @date 2024/2/19 20:58
 */
@RestController
@RequestMapping("/public/admin")
public class PublicAdminController {
    @Autowired
    private SystemUserService systemUserService;

    /**
     * 用户登录
     *
     * @param request
     * @return
     */
    @PostMapping("/user/login")
    public R<SaTokenInfo> login(@RequestBody SystemUserLoginDto request) {
        SaTokenInfo loginToken = systemUserService.login(request);
        return R.ok(loginToken);
    }

    /**
     * 用户注册
     *
     * @param request
     * @return
     */
    @PostMapping("/user/register")
    public R<SaTokenInfo> register(@RequestBody SystemUserLoginDto request) {
        SaTokenInfo registerToken = systemUserService.register(request);
        return R.ok(registerToken);
    }

    /**
     * 退出登录
     *
     * @return
     */
    @PostMapping("/role")
    public R getRoleList() {
        List<SystemRole> systemRoleList = systemUserService.getRoleList();
        return R.ok(systemRoleList);
    }
}
